<template>
  <el-container id="home">
    <el-header class="header">
      <div>
        <img src="@/assets/images/logo.png" alt="">
        <div>电商后台管理系统</div>
      </div>
      <div>
        <el-button type="info" @click="loginOut">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '65px':'200px'">
        <div class="toggleBtn" @click="toggle">|||</div>
        <el-menu
                 :collapse="isCollapse"
                 :collapse-transition="false"
                 default-active="2"
                 :unique-opened="true"
                 class="el-menu-vertical-demo"
                 background-color="#333744"
                 text-color="#fff"
                 active-text-color="#ffd04b"
                 :router="true"
        >
          <el-submenu v-for="(item,index) in list" :index="item.id+''" :key="index">
            <template slot="title">
              <i :class="icon[index].icon"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item-group v-for="i in item.children" :key="i.id">
              <el-menu-item :index="i.id+''" @click="go(i)">
                {{ i.authName }}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main calss="Main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import {menus,} from '@/utils/api'

export default {
  name: '',
  props: {},
  data() {
    return {
      state: true, isCollapse: false, list: [], icon: [
        {id: 1, icon: 'el-icon-s-custom'},
        {id: 2, icon: 'el-icon-s-cooperation'},
        {id: 3, icon: 'el-icon-s-goods'},
        {id: 4, icon: 'el-icon-s-order'},
        {id: 5, icon: 'el-icon-s-platform'},
      ]
    };
  },
  // 子组件转换
  components: {},
  // 数据引入 created
  created() {
    menus().then(res => {
      // console.log(res)
      this.list = res
    })
  },
  mounted() {
  },
  //点击函数事件
  methods: {
    //退出登录
    loginOut() {
      sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
    toggle() {
      this.isCollapse = !this.isCollapse;
    },
    go(i) {
      // console.log(i)
      this.$router.push({
        path: '/' + i.path,
        query: i
      })
    }
  },
  //计算事件
  computed: {},
  //数据监听
  watch: {},
  //过滤器
  filters: {},
  //设定自定义指令
  directives: {},
}
</script>
<style lang="scss" scoped>
#home {
  width: 100%;
  height: 100%;
  font-size: 24px;
  transition: all 3s;

  .header {
    width: 100%;
    height: 30px;
    background: #373D41;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .header > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;

    div {
      margin-left: 20px;
      color: #ffffff;
    }
  }

  .content {
    width: 100%;
    display: flex;
  }

  .Aside {
    background: #717171;
    flex: 1;
  }

  .Main {
    flex: 9;
    background: #cccccc;
  }

}

.el-container {
  height: 100%;
}

.el-aside {
  background: #333744;
  // height: 100vh;  //vw,vh
}

.toggleBtn {
  color: #ccc;
  text-align: center;
  line-height: 30px;
  background: #333;
  width: 100%;
  cursor: pointer;
  overflow-y: hidden;
}

</style>